package com.company.Thread;

/**
 * 叫到vip的概率高
 *
 *
 */

class Vip implements  Runnable {

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            //模拟练车时间
            try {
                Thread.sleep(3000);
            }catch (Exception e){
                e.printStackTrace();
            }
            System.out.println("Vip 开始");
        }
    }
}
class Num implements  Runnable{
     private Thread v;
     public  Num(){

     };

     public Num(Thread v){
         this.v=v;
     }
    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {
            if (i==19){
                //让给vip先执行 （在实现时：需要用 Join（）强制让vip插队，保证概率问题）
                try {
                    v.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            try {
                Thread.sleep(1000);
            }catch (Exception e){
                e.printStackTrace();
            }
            System.out.println("普通 开始");
        }
    }
}



public class ThreadTest2  {

    public static void main(String[] args) {
        Thread vip = new Thread(new Vip());

        Thread num = new Thread(new Num(vip));
        vip.start();
        num.start();
    }
}
